# -*- coding: utf-8 -*-
from abc import ABC

from app.views import CommonHandler
from app.models.dao import db2vectors, delete, add
from app.models.model import WarningModel


class WarningHandler(CommonHandler, ABC):
    async def get(self):
        meta_id = self.get_argument("meta_id", None)
        warnings = db2vectors(WarningModel, meta_id)
        await self.response(data=warnings)

    async def post(self):
        params = self.json_params()
        warning = WarningModel(params['points'], params['meta_id'])
        warning.dxftype = params['type']
        add(warning)
        warnings = db2vectors(WarningModel, params['meta_id'])
        await self.response(data=warnings)

    async def delete(self):
        params = self.json_params()
        delete(WarningModel, params['id'])
        warnings = db2vectors(WarningModel, params['meta_id'])
        await self.response(data=warnings)
